package com.grq.mis.validate;

import cn.hutool.core.lang.Validator;
import com.grq.mis.entity.Item;
import com.grq.mis.exception.BusinessException;
import com.grq.mis.exception.ResultEnum;

public class ItemValidate {

    public static void add(Item item) {

        if (Validator.isEmpty(item.getTitle())){
            throw new BusinessException(ResultEnum.PARAM_ERROR,"商品名称不能为空");
        }
        if (item.getPrice()==null){
            throw new BusinessException(ResultEnum.PARAM_ERROR,"商品价格不能为空");
        }
        if (item.getTotalCount() == null){
            throw new BusinessException(ResultEnum.PARAM_ERROR,"商品库存不能为空");
        }

    }

    public static void update(Item item) {
        if (item.getId() == null) {
            throw new BusinessException(ResultEnum.PARAM_ERROR,"商品编号不能为空");
        }
        if (Validator.isEmpty(item.getTitle())){
            throw new BusinessException(ResultEnum.PARAM_ERROR,"商品名称不能为空");
        }
        if (item.getPrice()==null){
            throw new BusinessException(ResultEnum.PARAM_ERROR,"商品价格不能为空");
        }
        if (item.getTotalCount() == null){
            throw new BusinessException(ResultEnum.PARAM_ERROR,"商品总数量不能为空");
        }
        if (item.getLeftCount() == null){
            throw new BusinessException(ResultEnum.PARAM_ERROR,"商品库存不能为空");
        }
    }
}
